package com.xinghua.web.mysqldb;

import java.sql.*;

public class XingHuadb {
    private Connection conn;

    public void mysqlconnect() throws SQLException {
        String url = "jdbc:mysql://localhost:3306/xinhua";
        String username = "root";
        String password = "123456";
        conn = DriverManager.getConnection(url, username, password);
    }

    public void insert(String timer, String center) {
        try {
            mysqlconnect(); // 建立连接
            String sql = "INSERT INTO xhdb(clock, center) VALUES(?, ?);";
            try (PreparedStatement statement = conn.prepareStatement(sql)) {
                statement.setString(1, timer);
                statement.setString(2, center);
                statement.executeUpdate();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}